import Vue from 'vue'
export function request(info){
	var url = info.url;
	var method = info.method;
	var params=info.params||{};
	var header=info.header||{};
	params  = filterParam(params)
	if(method==="get"){
		return Vue.prototype.$u.get(url,params,header)
	}
	if(method==="post"){
		return Vue.prototype.$u.post(url,params,header)
	}
	if(method==="put"){
		return Vue.prototype.$u.put(url,params,header)
	}
	if(method==="delete"){
		//拼接url 防止delete找不到参数
		return Vue.prototype.$u.delete(url+"?"+getParam(params),params,header)
	}
}

function filterParam(param){//过滤参数
	var data = {}
	for(let i in param){
		if(param[i]!==null && param[i]!==undefined && param[i]!==""){
			data[i] = param[i]
		}
	}
	return data;
}

function getParam(data){
    let url = '';
    for(var k in data){
        let value = data[k];
        url += `&${k}=${encodeURIComponent(value)}`
    }
     return url ? url.substring(1) : ''
}